package com.gdth.bank.presenter;

import android.util.Log;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.greendao.query.QueryBuilder;
import org.json.JSONException;
import org.json.JSONObject;

import com.gdth.bank.BankApplication;
import com.gdth.bank.bean.DbjjItem;
import com.gdth.bank.bean.DownloadBean;
import com.gdth.bank.bean.TAppGmjjdjJc;
import com.gdth.bank.event.MessageEvent;
import com.gdth.bank.model.CjkhjlModel;
import com.gdth.bank.model.DownloadModel;
import com.gdth.bank.model.SynchronizeModel;
import com.gdth.bank.model.TAppCanshuModel;
import com.gdth.bank.model.TXtBmModel;
import com.gdth.bank.utils.AppUtil;
import com.gdth.bank.utils.LogUtils;
import com.gdth.bank.utils.NotificationUtil;
import com.gdth.bank.utils.SharedPreferencesUtil;
import com.gdth.bank.view.GmJjDjView;
import com.gdth.bank.view.HuoDongDjView;

import com.gdth.database.bean.NotificationT;
import com.gdth.database.bean.TAppBfrjJbxxb;
import com.gdth.database.bean.TAppFjxxb;
import com.gdth.database.bean.TAppFjxxbDao;
import com.gdth.database.bean.TAppYh;
import com.gdth.database.bean.TXtBm;
import com.gdth.model.ImageItem;
import com.gdth.model.Item;
import com.gdth.resource.Constant;
import com.gdth.utils.GZIPUtils;
import com.gdth.utils.GsonUtil;
import com.gdth.widget.dialog.BaseToast;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;


import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SynchronizePresenter {
	
	private static final String tag = "SynchronizePresenter";
	SynchronizeModel mSynchronizeModel;
	CjkhjlModel mCjkhjlModel;
	TAppCanshuModel mToolModel;
	TXtBmModel mTXtBmModel;
	HuoDongDjView  mHuoDongDjView;
	GmJjDjView mGmJjDjView;
	public SynchronizePresenter(){
		this.mSynchronizeModel = new SynchronizeModel();
		this.mCjkhjlModel = new CjkhjlModel();
		this.mToolModel = new TAppCanshuModel();
		this.mTXtBmModel = new TXtBmModel();
		this.mHuoDongDjView=mHuoDongDjView;
	}
	public SynchronizePresenter(HuoDongDjView mHuoDongDjView){
		this.mHuoDongDjView=mHuoDongDjView;
		this.mSynchronizeModel = new SynchronizeModel();
	}
	public SynchronizePresenter(GmJjDjView mGmJjDjView){
		this.mGmJjDjView=mGmJjDjView;
		this.mSynchronizeModel = new SynchronizeModel();
	}
	
	
	/**
	*  获取服务器通知数据			
	*/
	public  void getNotificationList() {
		LogUtils.e("__________________", "______________" + "我来获取通知的了啊");
		
		String sfz = BankApplication.mInstance.getCurrentUser().getSfz();
		String lastid = SharedPreferencesUtil.getSharePreferencesByKey(BankApplication.mInstance,AppUtil.NOTIFICATION, AppUtil.LAST_NOTIFICATION_ID);
		if(lastid.equals("")) {
			lastid = "0";
		}
		 Gson gson2 = new GsonBuilder().enableComplexMapKeySerialization().create();  
		 Map<String, Object> map = new HashMap<String, Object>();  
		 map.put("jsruuid", sfz);
		 map.put("xxid",lastid );
		 String content = gson2.toJson(map) ;
		mSynchronizeModel.NotificationList(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io())
		.subscribe(new Subscriber<String>(){
	
			@Override
			public void onCompleted() {
				LogUtils.e(tag, "获取拜访日志完成");
			}
	
			@Override
			public void onError(Throwable arg0) {
				LogUtils.e(tag, "获取拜访日志失败：" + arg0);
			}
	
			@Override
			public void onNext(String arg0) {
				LogUtils.e(tag, "获取数据成功：");
				Gson mGson = GsonUtil.getGson();
			     try {
			    	 JSONObject jsonobject = new JSONObject(arg0);
			    
					 String content = jsonobject.getString("data");
					 List<NotificationT> mList =GsonUtil.getGson().fromJson(content, new TypeToken<List<NotificationT>>() {}.getType());
					 if(mList == null || mList.size() == 0)
						 return;
					 SynchronizeModel mSynchronizeModel = new SynchronizeModel();
					 mSynchronizeModel.saveNotifitionList(mList);
					 EventBus.getDefault().post(new MessageEvent(MessageEvent.NOTIFICATION_NEWDATA, content));
					 for(int i = 0 ; i < mList.size();i ++) {
						 NotificationUtil notificationUtil =new  NotificationUtil(BankApplication.mInstance);
						 notificationUtil.sendNotification(BankApplication.mInstance,mList.get(i));
					 }
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}
	public void changeListStatus() {
		mSynchronizeModel.changeListStatus();
	}
		
	/**
	 * 上传客户信息
	 */
	public void upLoadCjkhxx(){
		if(Constant.isOpenNotification) {
			getNotificationList();
		}
		String val = mSynchronizeModel.getAllCjkhxxByZt();
		if (val == null)
			return;
		
		mSynchronizeModel.upLoadCjkhxx(val)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(AndroidSchedulers.mainThread()) //AndroidSchedulers.mainThread()
		.subscribe(new Subscriber<String>(){
			
			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				BaseToast.getInstance().ShowSystemToast(BankApplication.mInstance.getBaseContext(), "上传采集客户信息成功");
			}
			
			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				BaseToast.getInstance().ShowSystemToast(BankApplication.mInstance.getBaseContext(), "上传采集客户信息失败：" + arg0);
			}
			
			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				mSynchronizeModel.UpdateZtForBfrj(arg0);
			}
			
		});
	}
	
	
	
	public void panduanWl(){
		mSynchronizeModel.getWl("")
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io()) //AndroidSchedulers.mainThread()
		.subscribe(new Subscriber<String>(){
			
			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
//				BaseToast.getInstance().ShowSystemToast(BankApplication.mInstance.getBaseContext(), "上传采集客户信息成功");
			}
			
			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				//BaseToast.getInstance().ShowSystemToast(BankApplication.mInstance.getBaseContext(), "网络连接失败：" + arg0);
			}
			
			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				if(!arg0.equals("")){
					upLoadFile();
				}
			}
		});
	}

	/**
	 * 上传文件
	 */
	public void upLoadFile(){
		TAppFjxxbDao dao = BankApplication.getDaoSession().getTAppFjxxbDao();
		QueryBuilder<TAppFjxxb> qb = dao.queryBuilder();
		qb.where(TAppFjxxbDao.Properties.Sczt.eq(0), TAppFjxxbDao.Properties.Gnmk.eq(1));
		List<TAppFjxxb> mList = qb.list();
		for (TAppFjxxb mTAppFjxxb : mList) {
			DownloadBean bean = new DownloadBean();
			bean.setName(mTAppFjxxb.getWjmc());
			bean.setWjlx(mTAppFjxxb.getWjlx());
			bean.setUuid(mTAppFjxxb.getUuid());
			bean.setWybs(mTAppFjxxb.getWybs());
			bean.setLocalPath(mTAppFjxxb.getAppdz());
			bean.setSqrsfz(mTAppFjxxb.getSfz());
			bean.setScms(0);
			bean.setCjsj(new Date());
			bean.setGnmk(1);
			bean.setFjlx(mTAppFjxxb.getFjlx());
			mTAppFjxxb.setSczt(3);
			dao.insertOrReplace(mTAppFjxxb);
			DownloadModel.getInstance().upload(bean);
		}
	}


	/**
	 * 获取机构部门信息
	 */
	public void getAllBm(){
		LogUtils.e(tag, "更新部门信息");
		mTXtBmModel.getBmOnline()
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(Schedulers.io())
			.subscribe(new Subscriber<String>(){
	
				@Override
				public void onCompleted() {
					LogUtils.e(tag, "获取部门数据成功");
				}
	
				@Override
				public void onError(Throwable arg0) {
					LogUtils.e(tag, "获取部门数据失败：" + arg0.getMessage());
				}
	
				@Override
				public void onNext(String arg0) {
					List<TXtBm> mList = new ArrayList<TXtBm>();

					JsonArray array = GsonUtil.getJsonArray(arg0);
					if (array == null)
						return;
					
					for (JsonElement el : array){
						TXtBm bm = GsonUtil.getGson().fromJson(el, TXtBm.class);
						
						mList.add(bm);
					}
					
					if (mList.size() == 0)
						return;
					
					mTXtBmModel.saveBm(mList);
				}
			
		});
	}
	
	/**
	 * 更新用户信息
	 */
	public void getUserData() {
		String json = BankApplication.mInstance.getCurrentUserForJson();
		if (json == null) 
			return;
		
		LogUtils.e(tag, "更新用户");
		TAppYh user = GsonUtil.getGson().fromJson(json, TAppYh.class);
		String zh = user.getZh();
		String content = "[{\"zh\":\""+zh+"\"}]";
		
		mSynchronizeModel.getYhForUpdate(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取用户数据完成");
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "更新用户信息失败："+arg0.getMessage());
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取用户数据成功：");
			}
		});
	}
	
	/**
	 * 首次登录获取所有采集客户记录
	 */
	public void getAllBfrj() {
		String json = BankApplication.mInstance.getCurrentUserForJson();
		if (json == null || json.equals("") || json.equals("[]")) 
			return;
		TAppYh user = GsonUtil.getGson().fromJson(json, TAppYh.class);
		String zh = user.getZh();
		//String content = "{\"zh\":\""+zh+"\"}";
		String content = "{\"zh\":\""+zh+"\",\"sfys\":\"true\"}";
		
		LogUtils.e(tag, "获取所有拜访日志");
		mSynchronizeModel.getAllBfrj(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取拜访日志完成");
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取拜访日志失败：" + arg0);
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub

				LogUtils.e(tag, "获取数据成功：");
				
				Gson mGson = GsonUtil.getGson();
				
				//解压拜访记录数据
				arg0 = GZIPUtils.uncompress(arg0);
				
				JsonArray array = GsonUtil.getJsonArray(arg0);
				List<TAppBfrjJbxxb> mList = new ArrayList<TAppBfrjJbxxb>();
				if (array == null || array.size() == 0) 
					return;
				for (JsonElement el : array) {
					TAppBfrjJbxxb mCjkhjl = mGson.fromJson(el, TAppBfrjJbxxb.class);
					mList.add(mCjkhjl);
				}
				mSynchronizeModel.saveAllBfrj(mList);

				LogUtils.e(tag, "拜访日志保存完成");
			}
		});
	}
	/**
	 * 首次当前活动
	 */
	public void gethddj(String content) {
		mSynchronizeModel.gethddj(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取拜访日志完成");
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取拜访日志失败：" + arg0);
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub

				LogUtils.e(tag, "获取数据成功：");
				
				Gson mGson = GsonUtil.getGson();
				
				JsonArray array = GsonUtil.getJsonArray(arg0);
				List<ImageItem> mList = new ArrayList<ImageItem>();
				if (array == null || array.size() == 0) 
					return;
				if(array.size()>0){
					for(int i=0;i<array.size();i++){
						ImageItem mImageItem=new ImageItem();
						JsonObject json=array.get(i).getAsJsonObject();
						mImageItem.setKey(json.get("id").getAsString());
						mImageItem.setValue(json.get("hdmc").getAsString());
						mImageItem.setGnlj("hddjxx");
						mList.add(mImageItem);
					}
				}
				mHuoDongDjView.updateHddj(mList);
				
			}
		});
	}
	/**
	 * 首次当前活动
	 */
	public void getBmList(String content) {
		mSynchronizeModel.getBmList(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(Schedulers.io())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取拜访日志失败：" + arg0);
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "获取拜访日志失败：" );
				
				Gson mGson = GsonUtil.getGson();
				
				JsonArray array = GsonUtil.getJsonArray(arg0);
				
				List<Item> mList = new ArrayList<Item>();
				if (array == null || array.size() == 0) 
					return;
				if(array.size()>0){
					for(int i=0;i<array.size();i++){
						Item mItem=new Item();
						JsonObject json=array.get(i).getAsJsonObject();
						mItem.setKey(json.get("ZH").getAsString());
						mItem.setValue(json.get("XM").getAsString());
						mList.add(mItem);
					}
				}
				mGmJjDjView.getBmList(mList);
				
				
			}
		});
	}
	public void saveqbList(String content) {
		mGmJjDjView.showProgressDialog("提交数据");
		mSynchronizeModel.saveqbList(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(AndroidSchedulers.mainThread())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				mGmJjDjView.showMessage("提交成功");
				mGmJjDjView.hideProgressDialog();
				mGmJjDjView.scsuccess();
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				mGmJjDjView.showMessage("提交失败");
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "：" + arg0);
				JsonArray array = GsonUtil.getJsonArray(arg0);
				Gson gson =GsonUtil.getGson();
 				List<TAppGmjjdjJc> mDTAppGmjjdjJcList = new ArrayList<TAppGmjjdjJc>();
 				for(JsonElement el : array){
 					TAppGmjjdjJc  mTAppGmjjdjJc= gson.fromJson(el, TAppGmjjdjJc.class);
 					mDTAppGmjjdjJcList.add(mTAppGmjjdjJc);
 				}
 			List<TAppFjxxb> fjlist= mDTAppGmjjdjJcList.get(0).getFjxxs();
 			int jcId=mDTAppGmjjdjJcList.get(0).getJcId();
 			if(fjlist==null || fjlist.size()==0){
 				
 			}else{
 				upLoadFileGmjj(fjlist,jcId);
 			}
 			
 			
				
			}
		});
	}
	public void savegxqbList(String content) {
		mGmJjDjView.showProgressDialog("提交数据");
		mSynchronizeModel.savegxqbList(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(AndroidSchedulers.mainThread())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				mGmJjDjView.showMessage("提交成功");
				mGmJjDjView.hideProgressDialog();
				mGmJjDjView.scsuccess();
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				mGmJjDjView.showMessage("提交失败");
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "：" );
				JsonArray array = GsonUtil.getJsonArray(arg0);
				Gson gson =GsonUtil.getGson();
 				List<TAppGmjjdjJc> mDTAppGmjjdjJcList = new ArrayList<TAppGmjjdjJc>();
// 				for(JsonElement el : array){
// 					TAppGmjjdjJc  mTAppGmjjdjJc= gson.fromJson(el, TAppGmjjdjJc.class);
// 					mDTAppGmjjdjJcList.add(mTAppGmjjdjJc);
// 				}
 				Iterator it=array.iterator();
 				while(it.hasNext()){
 					JsonElement e=(JsonElement) it.next();
 					TAppGmjjdjJc  mTAppGmjjdjJc= gson.fromJson(e, TAppGmjjdjJc.class);
 					mDTAppGmjjdjJcList.add(mTAppGmjjdjJc);
 				}
 				//修改
 			List<TAppFjxxb> fjlist= mDTAppGmjjdjJcList.get(0).getFjxxs();
 			int jcId=mDTAppGmjjdjJcList.get(0).getJcId();
 			if(fjlist==null || fjlist.size()==0){
 				
 			}else{
 				upLoadFileGmjj(fjlist,jcId);
 			}
			}
		});
	}
	/**
	 * 上传文件
	 */
	public void upLoadFileGmjj(List<TAppFjxxb> mList,int jcId){
		for (TAppFjxxb mTAppFjxxb : mList) {

			DownloadBean bean = new DownloadBean();
			bean.setName(mTAppFjxxb.getWjmc());
			bean.setWjlx(mTAppFjxxb.getWjlx());
			bean.setUuid(mTAppFjxxb.getUuid());
			bean.setWybs(jcId+"");
			bean.setLocalPath(mTAppFjxxb.getAppdz());
			bean.setSqrsfz(mTAppFjxxb.getSfz());
			bean.setScms(0);
			bean.setCjsj(new Date());
			bean.setGnmk(4);
			bean.setZdlx(1);
			DownloadModel.getInstance().upload(bean);
		}
	}
	//获取待办交接ListView登记
	
	public void getDbjjdjList(String content) {
		mGmJjDjView.showProgressDialog("加载数据");
		mSynchronizeModel.getDbjjdjList(content)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(AndroidSchedulers.mainThread())
		.subscribe(new Subscriber<String>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				mGmJjDjView.showMessage("刷新成功");
				mGmJjDjView.hideProgressDialog();
				mGmJjDjView.scsuccess();
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				mGmJjDjView.hideProgressDialog();
				mGmJjDjView.showMessage("刷新失败");
			}

			@Override
			public void onNext(String arg0) {
				// TODO Auto-generated method stub
				LogUtils.e(tag, "：" );
				JsonArray array = GsonUtil.getJsonArray(arg0);
				Gson gson =GsonUtil.getGson();
 				List<DbjjItem> mDbjjItemList = new ArrayList<DbjjItem>();
 				for(JsonElement el : array){
 					DbjjItem  mDbjjItem= gson.fromJson(el, DbjjItem.class);
 					mDbjjItemList.add(mDbjjItem);
 				}
 			
 				mGmJjDjView.getDbList(mDbjjItemList);
 			
				
			}
		});
	}
	//获取待办交接登记详情
	
		public void getDbjjdjJson(String content) {
			mGmJjDjView.showProgressDialog("加载数据");
			mSynchronizeModel.getDbjjdjJson(content)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<String>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mGmJjDjView.showMessage("刷新成功");
					mGmJjDjView.hideProgressDialog();
//					mGmJjDjView.scsuccess();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mGmJjDjView.showMessage("刷新失败");
				}

				@Override
				public void onNext(String arg0) {
					// TODO Auto-generated method stub
					LogUtils.e(tag, "：" + arg0);
					JsonArray array = GsonUtil.getJsonArray(arg0);
					Gson gson =GsonUtil.getGson();
	 				List<TAppGmjjdjJc> mTAppGmjjdjJcList = new ArrayList<TAppGmjjdjJc>();
	 				for(JsonElement el : array){
	 					TAppGmjjdjJc  mTAppGmjjdjJc= gson.fromJson(el, TAppGmjjdjJc.class);
	 					mTAppGmjjdjJcList.add(mTAppGmjjdjJc);
	 				}
	 			
	 				mGmJjDjView.getdbjjdjList(mTAppGmjjdjJcList);
	 			
					
				}
			});
		}
		//获取办结交接ListView登记
		
		public void getbjjdjList(String content) {
			mGmJjDjView.showProgressDialog("加载数据");
			mSynchronizeModel.getbjjdjList(content)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<String>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mGmJjDjView.showMessage("刷新成功");
					mGmJjDjView.hideProgressDialog();
					mGmJjDjView.scsuccess();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mGmJjDjView.hideProgressDialog();
					mGmJjDjView.showMessage("刷新失败");
				}

				@Override
				public void onNext(String arg0) {
					// TODO Auto-generated method stub
					LogUtils.e(tag, "：" );
					JsonArray array = GsonUtil.getJsonArray(arg0);
					Gson gson =GsonUtil.getGson();
	 				List<DbjjItem> mDbjjItemList = new ArrayList<DbjjItem>();
	 				for(JsonElement el : array){
	 					DbjjItem  mDbjjItem= gson.fromJson(el, DbjjItem.class);
	 					mDbjjItemList.add(mDbjjItem);
	 				}
	 			
	 				mGmJjDjView.getDbList(mDbjjItemList);
	 			
					
				}
			});
		}
		//获取办结交接ListView下拉登记
		
				public void getbjjdjUpList(String content) {
					mGmJjDjView.showProgressDialog("加载数据");
					mSynchronizeModel.getbjjdjUpList(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新成功");
							mGmJjDjView.hideProgressDialog();
							mGmJjDjView.scsuccess();
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新失败");
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							LogUtils.e(tag, "：" );
							JsonArray array = GsonUtil.getJsonArray(arg0);
							Gson gson =GsonUtil.getGson();
			 				List<DbjjItem> mDbjjItemList = new ArrayList<DbjjItem>();
			 				for(JsonElement el : array){
			 					DbjjItem  mDbjjItem= gson.fromJson(el, DbjjItem.class);
			 					mDbjjItemList.add(mDbjjItem);
			 				}
			 			
			 				mGmJjDjView.getDbList(mDbjjItemList);
			 			
							
						}
					});
				}
				//获取办结交接ListView上拉登记
				
				public void getbjjdjOffList(String content) {
					mGmJjDjView.showProgressDialog("加载数据");
					mSynchronizeModel.getbjjdjOffList(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新成功");
							mGmJjDjView.hideProgressDialog();
							mGmJjDjView.scsuccess();
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新失败");
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							LogUtils.e(tag, "：" );
							JsonArray array = GsonUtil.getJsonArray(arg0);
							Gson gson =GsonUtil.getGson();
			 				List<DbjjItem> mDbjjItemList = new ArrayList<DbjjItem>();
			 				for(JsonElement el : array){
			 					DbjjItem  mDbjjItem= gson.fromJson(el, DbjjItem.class);
			 					mDbjjItemList.add(mDbjjItem);
			 				}
			 			
			 				mGmJjDjView.getDbList(mDbjjItemList);
			 			
							
						}
					});
				}
				
				public void getDbjjdjUpList(String content) {
					mGmJjDjView.showProgressDialog("加载数据");
					mSynchronizeModel.getDbjjdjUpList(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新成功");
							mGmJjDjView.hideProgressDialog();
							mGmJjDjView.scsuccess();
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新失败");
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							LogUtils.e(tag, "：");
							JsonArray array = GsonUtil.getJsonArray(arg0);
							Gson gson =GsonUtil.getGson();
			 				List<DbjjItem> mDbjjItemList = new ArrayList<DbjjItem>();
			 				for(JsonElement el : array){
			 					DbjjItem  mDbjjItem= gson.fromJson(el, DbjjItem.class);
			 					mDbjjItemList.add(mDbjjItem);
			 				}
			 			
			 				mGmJjDjView.getDbList(mDbjjItemList);
			 			
							
						}
					});
				}
				public void getDbjjdjOffList(String content) {
					mGmJjDjView.showProgressDialog("加载数据");
					mSynchronizeModel.getDbjjdjOffList(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新成功");
							mGmJjDjView.hideProgressDialog();
							mGmJjDjView.scsuccess();
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新失败");
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							//LogUtils.e(tag, "：" + arg0);
							JsonArray array = GsonUtil.getJsonArray(arg0);
							Gson gson =GsonUtil.getGson();
			 				List<DbjjItem> mDbjjItemList = new ArrayList<DbjjItem>();
			 				for(JsonElement el : array){
			 					DbjjItem  mDbjjItem= gson.fromJson(el, DbjjItem.class);
			 					mDbjjItemList.add(mDbjjItem);
			 				}
			 			
			 				mGmJjDjView.getDbList(mDbjjItemList);
			 			
							
						}
					});
				}
				
				/**
				 * 首次登录人岗位下拉
				 */
				public void getGwList(String content) {
					mSynchronizeModel.getGwList(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							LogUtils.e(tag, "获取岗位下拉失败：" + arg0);
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							LogUtils.e(tag, "获取岗位下拉失败：" + arg0);
							
							Gson mGson = GsonUtil.getGson();
							
							JsonArray array = GsonUtil.getJsonArray(arg0);
							
							List<Item> mList = new ArrayList<Item>();
//							if (array == null || array.size() == 0) 
//								return;
							if(array.size()>0){
								for(int i=0;i<array.size();i++){
									Item mItem=new Item();
									JsonObject json=array.get(i).getAsJsonObject();
									mItem.setKey(json.get("GW_ID").getAsString());
									mItem.setValue(json.get("GW_MC").getAsString());
									mList.add(mItem);
								}
							}
							mGmJjDjView.getGwList(mList);
							
							
						}
					});
				}
				
				//获取待办交接登记详情
				
				public void getdjJson(String content) {
					mGmJjDjView.showProgressDialog("加载数据");
					mSynchronizeModel.getdjJson(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新成功");
							mGmJjDjView.hideProgressDialog();
//							mGmJjDjView.scsuccess();
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("刷新失败");
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							LogUtils.e(tag, "：" + arg0);
							JsonArray array = GsonUtil.getJsonArray(arg0);
							Gson gson =GsonUtil.getGson();
			 				List<TAppGmjjdjJc> mTAppGmjjdjJcList = new ArrayList<TAppGmjjdjJc>();
			 				for(JsonElement el : array){
			 					TAppGmjjdjJc  mTAppGmjjdjJc= gson.fromJson(el, TAppGmjjdjJc.class);
			 					mTAppGmjjdjJcList.add(mTAppGmjjdjJc);
			 				}
			 			
			 				mGmJjDjView.getdjJson(mTAppGmjjdjJcList);
			 			
							
						}
					});
				}
				public void deletejson(String content) {
					mGmJjDjView.showProgressDialog("删除数据");
					mSynchronizeModel.deletejson(content)
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(AndroidSchedulers.mainThread())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("删除成功");
							mGmJjDjView.hideProgressDialog();
//							mGmJjDjView.scsuccess();
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							mGmJjDjView.showMessage("删除失败");
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
			 			if(arg0.equals("删除成功")){
			 				mGmJjDjView.deleteJson(arg0);
			 			}
							
						}
					});
				}
	
	public String uploadFileSize() {
		TAppFjxxbDao dao = BankApplication.getDaoSession().getTAppFjxxbDao();
		QueryBuilder<TAppFjxxb> qb = dao.queryBuilder();
		qb.where(TAppFjxxbDao.Properties.Sczt.eq(0), TAppFjxxbDao.Properties.Gnmk.eq(1));
		List<TAppFjxxb> mList = qb.list();
		if (null == mList || mList.size() == 0) {
			return "0";
		}
		return "1";
	}
	
	

				
}
